package cz.zcu.fav.rat.rest.factory;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cz.zcu.fav.rat.beans.Object;
import cz.zcu.fav.rat.dataaccess.service.UserService;
import cz.zcu.fav.rat.rest.beans.ObjectMapping;
import cz.zcu.fav.rat.security.beans.UserSessionController;

@Component
public class ObjectMappingFactory extends AbstractMappingFactory<ObjectMapping, Object>
{
	@Autowired
	UserService userService;
	
	@Override
	public ObjectMapping getObject() throws Exception
	{
		return new ObjectMapping();
	}

	@Override
	public Class<?> getObjectType()
	{
		return ObjectMapping.class;
	}

	@Override
	public ObjectMapping getMappedObject(Object object)
	{
		ObjectMapping mapping = new ObjectMapping();
		mapping.setPickable(object.getObjectClass().isPickable());
		mapping.setReturnable(object.getObjectClass().isReturnable());
		mapping.setDescription(object.getDescription());
		mapping.setId(object.getId());
		mapping.setIdentifier(object.getIdentifier());
		mapping.setName(object.getName());
		mapping.setFavourite(userService.isObjectUsersFavourite(
				UserSessionController.getLoggedUserBean().getId(),
				object.getId()));
		mapping.setObjectclassId(object.getObjectClass().getId());
		mapping.setObjectClassName(object.getObjectClass().getName());
		return mapping;
	}

	@Override
	public Object getRemappedObject(ObjectMapping object, boolean ignoreId)
	{
		throw new UnsupportedOperationException();
		// not necessary to implement yet
	}

}
